﻿using ConfExpert.Forms.Base;
using ConfExpert.Utility.Peripheral;
using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevTeam;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace ConfExpert.Forms.Ithalat
{
    public partial class MasrafFaturasi : XForm
    {
        const int CONST_EXCEL_TEXTILE_ROW = 13;
        int TekstilExcelRow;
        RepositoryItemHyperLinkEdit riHyperLink = new RepositoryItemHyperLinkEdit();

        public MasrafFaturasi()
        {
            TekstilExcelRow = CONST_EXCEL_TEXTILE_ROW;
            InitializeComponent();
        }

        private void MasrafFaturasi_Load(object sender, EventArgs e)
        {
            gridView1.Init("GetMasrafFaturasi");
            gridView1.MakeColumnInvisible("MasrafFaturasiId", "InsertedOn", "FaturaId", "KesilenMasrafFaturasiId");
            gridView1.FormatAsNumber(2, "ToplamMasraf", "FaturalanacakTutar", "FaturalananTutar");
            gridView1.AddSummary("ToplamMasraf", "FaturalanacakTutar", "FaturalananTutar");
            gridView1.MakeReadOnly("FaturalananTutar", "DovizCinsi2Id", "KarbelInvNo", "KarbelInvTarihi");

            gridView2.Init("GetMasrafFaturasiScan");

            btnKaydet.ItemClick += btnKaydet_ItemClick;
            gridView1.RowCellStyle += gridView1_RowCellStyle;
            gridView2.RowCellClick += gridView2_RowCellClick;

            /*
            GridManager gmx = GridManager.GetManager(gridView1);
            gmx.GridMenu.AddMenu("Seçili Satırlar İçin Fatura Oluştur", FaturaOlustur);
            GridManager gm2 = GridManager.GetManager(gridView1);
            gm2.GridMenu.AddMenu("Seçili Satırlar İçin Fatura Sil", FaturaSil);*/


            GridManager gm2 = GridManager.GetManager(gridView1);
            gm2.GridMenu.AddMenu("ToplamMasraf'ı girilen parabirimine çevir", DovizCevir);
            gm2.GridMenu.AddMenu("Faturayı Göster", FaturayiGoster);

            GridManager gm = GridManager.GetManager(gridView2);
            gm.GridMenu.AddMenu("Scan", FaturaTara);
            //satır silmeye karşı önlem al!

            //gridView1.Columns["KarbelInvNo"].ColumnEdit = riHyperLink;
            //gridView1.RowCellClick += gridView1_RowCellClick;

            gridView1.BestFitColumns();
            gridView2.BestFitColumns();

            ExpandCollapse(splitContainerControl1, AcKapa.Collapse);
        }

        /*
        void gridView1_RowCellClick(object sender, RowCellClickEventArgs e)
        {
            if (e.RowHandle < 0)
                return;

            Cursor.Current = Cursors.WaitCursor;

            DataRow dr = gridView1.GetDataRow(e.RowHandle);

            switch (e.Column.FieldName)
            {
                case "KarbelInvNo":
                    int KesilenMasrafFaturasiId = gridView1.GetDataRow(gridView1.FocusedRowHandle)["KesilenMasrafFaturasiId"].ToInt();
                    if (KesilenMasrafFaturasiId > 0)
                    {
                        DataTable t = Session.DataManager.ExecuteDataTable("GetKesilenMasrafFaturasi", KesilenMasrafFaturasiId);
                        FileToSend = ByteArrayToFile3(t.Rows[0]["FaturaNo"].ToString() + t.Rows[0]["Ext"].ToString(), t.Rows[0]["Dosya"] as byte[]);

                        System.Diagnostics.Process process = new System.Diagnostics.Process();
                        process.StartInfo.FileName = FileToSend;
                        process.Start();
                    }
                    break;
            }


            Cursor.Current = Cursors.Default;
        }
        */

        void DovizCevir(object sender, EventArgs e)
        {
            for (int i = 0; i < gridView1.SelectedRowsCount; i++)
            {
                DataRow row = gridView1.GetDataRow(gridView1.GetSelectedRows()[i]);

                double GunlukKur = 0;
                int CurrencyId = row["DovizCinsi2Id"].ToInt();
                switch (CurrencyId)
                {
                    case 2: GunlukKur = Session.Usd; break;
                    case 1: GunlukKur = Session.Eur; break;
                    case 3: GunlukKur = Session.Gbp; break;
                    default:
                        GunlukKur = 1.0d; break;
                }

                if (GunlukKur > 0)
                    row["FaturalananTutar"] = row["ToplamMasraf"].ToDecimal() / (decimal)GunlukKur;
            }
        }

        void FaturayiGoster(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            DataRow dr = gridView1.GetFocusedDataRow();

            int KesilenMasrafFaturasiId = gridView1.GetDataRow(gridView1.FocusedRowHandle)["KesilenMasrafFaturasiId"].ToInt();
            if (KesilenMasrafFaturasiId > 0)
            {
                DataTable t = Session.DataManager.ExecuteDataTable("GetKesilenMasrafFaturasi", KesilenMasrafFaturasiId);
                FileToSend = ByteArrayToFile3(t.Rows[0]["FaturaNo"].ToString() + t.Rows[0]["Ext"].ToString(), t.Rows[0]["Dosya"] as byte[]);

                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.StartInfo.FileName = FileToSend;
                process.Start();
            }

            Cursor.Current = Cursors.Default;
        }

        Scanner.PhotosTable photosTable = new Scanner.PhotosTable();
        void FaturaTara(object sender, EventArgs e)
        {
            DataRow drx = gridView2.GetDataRow(gridView2.FocusedRowHandle);
            string InvNo = drx["KarbelInvNo"].ToString();

            try
            {
                this.Cursor = Cursors.WaitCursor;

                Image scanned = Scanner.ScanA4();
                photosTable = new Scanner.PhotosTable();
                DataRow dr = photosTable.AddFaturaRow(InvNo, scanned);
                ExecuteNonQuery("UpdPhotoFatura", photosTable.Table, WhoAmI);
                gridView2.RefreshDataSource("GetMasrafFaturasiScan");

                GC.Collect();

                Notify("Tarama İşlemi Başarıyla Gerçekleşti.");
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        //int UpdPhotoFatura(params object[] p)
        //{
        //    using (SqlConnection sqlConn = new SqlConnection(Session.DataManager.ConnectionString))
        //    {
        //        sqlConn.Open();
        //        SqlCommand sqlCmd = sqlConn.CreateCommand();
        //        sqlCmd.CommandText = "UpdPhotoFatura";
        //        sqlCmd.CommandType = CommandType.StoredProcedure;
        //        SqlParameter[] parameters = new SqlParameter[2];
        //        parameters[0] = new SqlParameter("@tbl", SqlDbType.Structured);
        //        parameters[0].Value = p[0];
        //        parameters[1] = new SqlParameter("@UserId", SqlDbType.Int);
        //        parameters[1].Value = p[1];
        //        sqlCmd.Parameters.AddRange(parameters);
        //        return sqlCmd.ExecuteScalar().ToInt();
        //    }
        //}

        void gridView2_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            if (e.RowHandle < 0)
                return;

            Cursor.Current = Cursors.WaitCursor;

            if (e.Column.FieldName == "Tarama")
            {
                DataRow dr = gridView2.GetDataRow(e.RowHandle);
                string FATURANO = dr["KarbelInvNo"].ToStr();
                if (FATURANO != string.Empty &&
                    dr["Tarama"].ToStr() != string.Empty)
                {
                    DataTable dtDosya = ExecuteDataTable("GetFaturaPhoto", FATURANO);

                    byte[] bytes = (byte[])dtDosya.Rows[0]["Dosya"];
                    string FileName = FATURANO + ".png";

                    DevTeam.FileManager.RunTempFile(FileName, bytes);
                }
            }

            Cursor.Current = Cursors.Default;
        }

        void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (e.RowHandle > -1)
            {
                switch (e.Column.FieldName)
                {
                    case "ToplamMasraf":
                    case "FaturalanacakTutar":
                    case "FaturalananTutar":
                        e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
                        return;
                }
            }
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.Update("MasrafFaturasiId,FaturalananTutar,DovizCinsi2Id,KarbelInvNo,KarbelInvTarihi", "MasrafFaturasi");
            gridView1.RefreshDataSource("GetMasrafFaturasi");
            gridView1.BestFitColumns();

            gridView2.RefreshDataSource("GetMasrafFaturasiScan");
            gridView2.BestFitColumns();
        }

        string FileToSend;
        string MasrafFaturasiIds;
        void FaturaOlustur(object sender, EventArgs e)
        {
            MasrafFaturasiIds = gridView1.GetSelectedValues("MasrafFaturasiId");

            bool HepsiAyni = true;
            int FixedCustomerId = 0,
                newCustomerId = 0;
            int[] selRows = gridView1.GetSelectedRows();

            for (int i = 0; i < selRows.Length; ++i)
            {
                DataRow selRow = gridView1.GetDataRow(selRows[i]);
                if (i == 0)
                {
                    FixedCustomerId = selRow["CustomerId"].ToInt();
                }
                else
                {
                    newCustomerId = selRow["CustomerId"].ToInt();
                    if (FixedCustomerId == newCustomerId)
                        continue;
                    else
                        HepsiAyni = false;
                }

            }

            if (HepsiAyni)
            {
                if (UyariVerForSeciliSatirlarContainsMultipleKesilenMasrafFaturasiId(selRows))
                    return;

                if (UyariVerForSeciliSatirlarContainsKesilenMasrafFaturasiId(selRows))
                    return;

                DataTable resultDT = ExecuteDataTable("GetMasrafFaturasiFirmaBilgileri", FixedCustomerId);

                int TemplatesId = 0;
                if (((String)resultDT.Rows[0]["Ihracatci"]).Equals("KARBEL TEKSTİL"))
                    TemplatesId = 3;
                else if (((String)resultDT.Rows[0]["Ihracatci"]).Equals("KARBEL KONFEKSİYON"))
                    TemplatesId = 4;
                else
                    TemplatesId = -1;

                using (FaturaOlustur fo = new FaturaOlustur())
                {
                    if (fo.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        string kategori = "MasrafFaturasi";
                        //int TemplatesId = 3;
                        int CurrencyId;

                        if (TemplatesId > 0)
                        {
                            string sonuc = ExecuteScalar("GetCurrencyType", MasrafFaturasiIds).ToStr();

                            if (sonuc.StartsWith("Bu Müşteri"))
                            {
                                XtraMessageBox.Show(sonuc, "Uyarı");
                                return;
                            }
                            else
                            {
                                CurrencyId = sonuc.ToInt();
                            }

                            DataTable t = Session.DataManager.ExecuteDataTable("GetTemplates", kategori, TemplatesId);

                            // Save the workbook to a memory stream.
                            System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(t.Rows[0]["BLOB"] as byte[]);

                            // Create a simple workbook.
                            SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook();

                            // Create another workbook from the memory stream.
                            workbook = SpreadsheetGear.Factory.GetWorkbookSet().Workbooks.OpenFromStream(memoryStream);

                            workbook.Worksheets["INV"].Cells["H1"].Value = DateTime.Now.Date.ToString("dd.MM.yyyy");
                            workbook.Worksheets["INV"].Cells["H1"].HorizontalAlignment = SpreadsheetGear.HAlign.Right;
                            workbook.Worksheets["INV"].Cells["H2"].Value = fo.FaturaNo;

                            DataTable table = ExecuteDataTable("GetCustomerInfoForFatura", FixedCustomerId);
                            DataRow[] rows = table.Select();
                            workbook.Worksheets["INV"].Cells["B5"].Value = rows[0]["MusteriAdi"].ToStr();
                            workbook.Worksheets["INV"].Cells["B6"].Value = resultDT.Rows[0]["Adres1"].ToStr();
                            workbook.Worksheets["INV"].Cells["B7"].Value = resultDT.Rows[0]["Adres2"].ToStr();
                            workbook.Worksheets["INV"].Cells["B9"].Value = rows[0]["UlkeAdi"].ToStr();

                            workbook.Worksheets["INV"].Cells["B26"].Value = "Terms of Payment";
                            workbook.Worksheets["INV"].Cells["C26"].Value = "15 DAYS AFTER INVOICE DATE";

                            workbook.Worksheets["INV"].Cells["B27"].Value = "Bank";
                            workbook.Worksheets["INV"].Cells["C27"].Value = resultDT.Rows[0]["Bank"].ToStr(); //"H.S.B.C. BANK";

                            workbook.Worksheets["INV"].Cells["B28"].Value = "Branch";
                            workbook.Worksheets["INV"].Cells["C28"].Value = resultDT.Rows[0]["Branch"].ToStr(); //"İSTANBUL";

                            workbook.Worksheets["INV"].Cells["B29"].Value = "Swift Code";
                            workbook.Worksheets["INV"].Cells["C29"].Value = resultDT.Rows[0]["SwiftCode"].ToStr(); //"HSBCTRIX";

                            workbook.Worksheets["INV"].Cells["B30"].Value = "Acc. Nr";
                            workbook.Worksheets["INV"].Cells["C30"].Value = resultDT.Rows[0]["AccNr"].ToStr(); //"701-1021598-772-99 (EUR)";

                            workbook.Worksheets["INV"].Cells["B31"].Value = "Iban Nr";
                            workbook.Worksheets["INV"].Cells["C31"].Value = resultDT.Rows[0]["IbanNr"].ToStr(); //"TR370012300701102159877299";

                            workbook.Worksheets["INV"].Cells["B32"].Value = "From";
                            workbook.Worksheets["INV"].Cells["C32"].Value = "THE GOODS ARE OF TURKISH ORIGIN";
                            if (((String)resultDT.Rows[0]["Ihracatci"]).Equals("KARBEL TEKSTİL"))
                                workbook.Worksheets["INV"].Cells["B33"].Value = "GOODS REMAIN THE PROPERTY OF KARBEL TEKSTIL DIS TIC.LTD.STI. UNTIL PAID IN FULL.";
                            else
                                workbook.Worksheets["INV"].Cells["B33"].Value = "GOODS REMAIN THE PROPERTY OF KARBEL KONFEKSIYON SANAYI VE TICARET LTD.STI. UNTIL PAID IN FULL.";

                            TekstilExcelRow = CONST_EXCEL_TEXTILE_ROW;
                            for (int i = 0; i < selRows.Length; ++i)
                            {
                                DataRow selRow = gridView1.GetDataRow(selRows[i]);
                                ExceleDataRowYaz(ref workbook, ref selRow, CurrencyId);
                            }

                            System.IO.MemoryStream memoryStream2 = new System.IO.MemoryStream();
                            workbook.SaveToStream(memoryStream2, SpreadsheetGear.FileFormat.OpenXMLWorkbook);

                            // Close the workbook.
                            workbook.Close();

                            string DosyaAdi = t.Rows[0]["DosyaAdi"].ToString();
                            byte[] BLOB = memoryStream2.ToArray();
                            int KesilenMasrafFaturasiId = IlkKesilenMasrafFaturasiIdKaydi(selRows);
                            string result = ExecuteScalar("InsMasrafDosyasi", BLOB, fo.txtFaturaNo.Text, KesilenMasrafFaturasiId, MasrafFaturasiIds).ToStr();
                            MasrafFaturasiIds = string.Empty;

                            if (!result.Equals(String.Empty))
                            {
                                XtraMessageBox.Show(result, "Uyarı");
                                return;
                            }

                            gridView1.RefreshDataSource("GetMasrafFaturasi");
                            FileToSend = ByteArrayToFile3(DosyaAdi, BLOB);
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo.FileName = FileToSend;
                            process.Start();
                        }
                        else if (TemplatesId == -1)
                            XtraMessageBox.Show("'TemplatesMasrafFaturasi'ndan TemplatesId Doğru Alınamadı!", "Uyarı");
                    }
                }
            }
            else
            {
                XtraMessageBox.Show("Sadece Aynı Müşterileri Belirten Satırlar İçin Fatura Oluşturabilirsiniz!", "Uyarı");
            }
        }

        public bool UyariVerForSeciliSatirlarContainsKesilenMasrafFaturasiId(int[] selectedRows)
        {
            bool retVal = false;

            for (int i = 0; i < selectedRows.Length; ++i)
            {
                DataRow selRow = gridView1.GetDataRow(selectedRows[i]);
                if (selRow["KesilenMasrafFaturasiId"].ToInt() > 0)
                {
                    DialogResult result = XtraMessageBox.Show("Seçtiğiniz Satırlardan En Az Biri İçin Daha Önceden Oluşturulmuş Bir Masraf Faturası Var. İşleme Devam Ederseniz Eski Fatura Dosyasını Kaybetmiş Olacaksınız. Devam Etmek İstiyor Musunuz?", "Onay", MessageBoxButtons.YesNo);

                    if (result == System.Windows.Forms.DialogResult.No)
                        retVal = true;

                    break;
                }
            }

            return retVal;
        }

        public bool UyariVerForSeciliSatirlarContainsMultipleKesilenMasrafFaturasiId(int[] selectedRows)
        {
            int FirstMasrafFaturaId = -1,
                TutulanDeger = -1;
            bool HepsiAyniDegil = false;

            for (int i = 0; i < selectedRows.Length; ++i)
            {
                DataRow selRow = gridView1.GetDataRow(selectedRows[i]);
                FirstMasrafFaturaId = selRow["KesilenMasrafFaturasiId"].ToInt();

                if (FirstMasrafFaturaId == 0)
                    continue;
                else
                {
                    if (TutulanDeger == -1)
                        TutulanDeger = FirstMasrafFaturaId;
                    else if (TutulanDeger != FirstMasrafFaturaId)
                        HepsiAyniDegil = true;
                }
            }

            if (HepsiAyniDegil == true)
                XtraMessageBox.Show("Seçiminiz Birbirinden Farklı Fatura No Kayıtları İçermektedir!", "Uyarı");

            return HepsiAyniDegil;
        }

        public int IlkKesilenMasrafFaturasiIdKaydi(int[] selectedRows)
        {
            int retVal = 0,
                siradakiDeger;

            for (int i = 0; i < selectedRows.Length; ++i)
            {
                DataRow selRow = gridView1.GetDataRow(selectedRows[i]);
                siradakiDeger = selRow["KesilenMasrafFaturasiId"].ToInt();
                if (siradakiDeger != 0)
                {
                    retVal = siradakiDeger;
                    break;
                }
            }

            return retVal;
        }

        public string ByteArrayToFile3(string filePath, byte[] content)
        {
            string FullPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.InternetCache) + "\\" + filePath;
            using (FileStream fs = new FileStream(FullPath, FileMode.Create, FileAccess.Write))
            using (BinaryWriter bw = new BinaryWriter(fs))
            {
                bw.Write(content);
                bw.Flush();
            }


            return FullPath;
        }

        public void ExceleDataRowYaz(ref SpreadsheetGear.IWorkbook wb, ref DataRow dr, int CurrencyId)
        {
            string invNoSutun = "B" + TekstilExcelRow.ToStr();
            string invDateSutun = "C" + TekstilExcelRow.ToStr();
            string descriptionSutun = "D" + TekstilExcelRow.ToStr();
            string totalValueSutun = "H" + TekstilExcelRow.ToStr();

            if (TekstilExcelRow > 20)
            {
                string cellRange = TekstilExcelRow.ToStr() + ":" + TekstilExcelRow.ToStr();
                string rangeStr = "B" + TekstilExcelRow.ToStr() + ":H" + TekstilExcelRow.ToStr();

                wb.Worksheets["INV"].Cells[cellRange].Insert();
                wb.Worksheets["INV"].Cells[rangeStr].Borders.LineStyle = SpreadsheetGear.LineStyle.Dot;
                wb.Worksheets["INV"].Cells[rangeStr].Borders.Weight = SpreadsheetGear.BorderWeight.Hairline;
            }

            //int CurrencyId = dr["DovizCinsiId"].ToInt();
            string Currency = RepositoryManager.dsLookups.Tables["Currency"].Select("CurrencyId=" + CurrencyId.ToStr())[0]["Abbr"].ToStr();
            double GunlukKur;

            switch (Currency)
            {
                case "USD": GunlukKur = Session.Usd; break;
                case "EUR": GunlukKur = Session.Eur; break;
                case "GBP": GunlukKur = Session.Gbp; break;
                default:
                    GunlukKur = 1.0d; break;
            }
            dr["Tutar"] = dr["ToplamMasraf"].ToDecimal() / (decimal)GunlukKur;

            wb.Worksheets["INV"].Cells[invNoSutun].Value = dr["FaturaNo"].ToStr();
            wb.Worksheets["INV"].Cells[invDateSutun].Value = dr["FaturaTarihi"].ToDate().ToDate().ToString("dd.MM.yyyy");
            wb.Worksheets["INV"].Cells[descriptionSutun].Value = "Import Cost";
            wb.Worksheets["INV"].Cells[totalValueSutun].Value = dr["ToplamMasraf"].ToDecimal() / (decimal)GunlukKur;

            SpreadsheetGear.IRange range = wb.ActiveWorksheet.Cells[totalValueSutun];
            range.NumberFormat = @"#,##0.00 \" + Currency;

            TekstilExcelRow++;
        }

        string MasrafFaturasiIdleri;
        void FaturaSil(object sender, EventArgs e)
        {
            MasrafFaturasiIdleri = gridView1.GetSelectedValues("MasrafFaturasiId");

            bool SilinecekElemanVar = false;
            int SelecttedCustomerId = -1;
            List<int> SilinecekElemanlarList = new List<int>();

            int[] selRows = gridView1.GetSelectedRows();

            for (int i = 0; i < selRows.Length; ++i)
            {
                DataRow selRow = gridView1.GetDataRow(selRows[i]);
                SelecttedCustomerId = selRow["KesilenMasrafFaturasiId"].ToInt();
                if (SelecttedCustomerId != 0)
                {
                    SilinecekElemanlarList.Add(SelecttedCustomerId);
                    SilinecekElemanVar = true;
                }

            }

            if (SilinecekElemanVar)
            {
                string DelItemList = SilinecekElemanlarListesiOlustur(SilinecekElemanlarList);  // List<int> ten 11,12,13,14,... seklinde string e al
                string FaturaNoList = GetFaturaNoList(DelItemList);
                DialogResult result = XtraMessageBox.Show(FaturaNoList + " No'lu Fatura(lar) Silinecektir. Devam Etmek İstiyor Musunuz?", "Onay", MessageBoxButtons.YesNo);

                if (result == System.Windows.Forms.DialogResult.Yes)
                {
                    ExecuteNonQuery("DelMasrafDosyasi", DelItemList);  // DelItemList'i "in () query" de kullan
                    gridView1.RefreshDataSource("GetMasrafFaturasi");
                }
            }
            else
            {
                XtraMessageBox.Show("Seçtiğiniz Satırlarda Silinecek Fatura No Tesbit Edilemedi!", "Uyarı");
            }
        }

        public string SilinecekElemanlarListesiOlustur(List<int> list)
        {
            string retString = "";

            foreach (int e in list)
            {
                retString += e.ToStr() + ",";
            }

            retString = retString.Substring(0, retString.Length - 1); // Sondaki virgulu ayikla

            return retString;
        }

        public string GetFaturaNoList(string DelItemList)
        {
            string returnStr = "";
            string[] tokens;
            string retListe = ExecuteScalar("GetDosyaNoFromKesilenMasrafFaturasi", DelItemList).ToStr();

            tokens = retListe.Split(',');
            if (tokens.Length == 1)
            {
                returnStr = tokens[0];
            }
            else
            {
                int veBaglaciPozisyon = tokens.Length - 1;

                for (int i = 0; i < tokens.Length; ++i)
                {
                    if (i == 0)
                        returnStr = tokens[i];
                    else if (i == veBaglaciPozisyon)
                        returnStr += " ve " + tokens[i];
                    else
                        returnStr += ", " + tokens[i];
                }
            }

            return returnStr;
        }

        //!OAx
        /*
                        command.CommandText = @"insert into Logs (Data) values ( @data)";
                        command.Parameters.Add("@data", SqlDbType.VarBinary, data.Length).Value = data;
        */

    }
}